﻿Imports System.Data.SqlClient


Public Class WebForm1
    Inherits System.Web.UI.Page
    'Dim connectionString As String = "Data Source=(localdb)\Projects;Initial Catalog=CIS441WinterParkWeb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False"
    'Dim connectionString As String = "Data Source=SHANK-PC\SQLEXPRESS;Initial Catalog=WinterPark;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False"
    Dim con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MainConn").ConnectionString)

    'Dim con As New SqlConnection(connectionString)
    Public UName As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click
        'Setup Login variables
        Dim UName As String = UNameTextBox.Text
        Dim Passwrd As String = PasswordTextBox.Text

        Dim LoginStatement As String = "SELECT * FROM Login where UserName='" & UName & "' and Password='" & Passwrd & "' "
        Dim LoginCmd As New SqlCommand(LoginStatement, con)
        con.Open()
        Dim LoginReader As SqlDataReader
        LoginReader = LoginCmd.ExecuteReader
        If LoginReader.Read Then
            Session("EmployeeID") = LoginReader.Item("EmployeeID").ToString
            Server.Transfer("MainMenu.aspx")
        Else
            Session("EmployeeID") = ""
            UNameTextBox.Text = ""
            PasswordTextBox.Text = ""
            TextBox3.Visible = True
            TextBox3.Text = "Invaild username or password!"
        End If

        'Dim LoginDataAdapter As New SqlDataAdapter(LoginStatement, con)
        'Dim LoginDataSet As New DataSet
        'LoginDataAdapter.Fill(LoginDataSet, "Login")


        'Dim dr As DataRow
        'For Each dr In LoginDataSet.Tables("Login").Rows
        'If dr.Item("UserName") = UName And dr.Item("Password") = Passwrd Then
        'If Not DBNull.Value.Equals(dr.Item("EmployeeID")) Then
        'Saving employee id within session
        'Session("EmployeeID") = dr.Item("EmployeeID").ToString
        'Else
        'Session("EmployeeID") = ""
        'End If
        'Server.Transfer("MainMenu.aspx")
        'Else
        'Continue For
        'End If
        'Next dr

        'TextBox1.Text = ""
        'TextBox2.Text = ""
        'TextBox3.Visible = True
        'TextBox3.Text = "Invaild username or password!"

    End Sub
    End Class
